import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes.js'

Vue.use(VueRouter)

const router = new VueRouter({
    mode: 'history',
    base: process.env.NODE_ENV === 'production' ? '/admin/' : '/',
  	routes
})


router.beforeEach((to,form, next) => {
	if (!localStorage.getItem('authorization') && to.path != '/login') {
		next({
			name : 'Login',
			replace : true
		})
	} else {
		next();
	}
})

export default router
